﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="MCB.Gaming.test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test</title>
    <script src="Scripts/engine.js" type="text/javascript"></script>
    <script src="Scripts/visualComponent.js" type="text/javascript"></script>
    <script src="Scripts/gameObjects.js" type="text/javascript"></script>
    <script type="text/javascript">
        var canvas;
        var context;
        var image;
        var engine;
        var playerShip;

        function hello() {
            
            //Load canvas and context
            canvas = document.getElementById('playArea');
            context = canvas.getContext('2d');
            
            //Load the prototype image
            image = new Image();
            image.src = "Tulip.jpg";
            image.x = 0;
            image.y = 0;
            
            //Setup engine
            engine = new Engine(context);

            image.onload = function () 
            {
                //Draw image to stage
                context.drawImage(image, 0, 0, 20, 20);

                var tulipData = context.getImageData(0, 0, 20, 20);

                playerShip = engine.add(new Ship(tulipData, 1, 1));
                engine.add(new VisualComponent(tulipData, 40, 40));
                engine.add(new VisualComponent(tulipData, 80, 90));
                engine.add(new VisualComponent(tulipData, 10, 60));
                engine.add(new VisualComponent(tulipData, 50, 150));
                engine.add(new VisualComponent(tulipData, 70, 140));

                engine.start();
            }
        }

        //Consumer moves
        function move() {
            var distance = 8;

            if (window.event && window.event.keyCode == 37)
                playerShip.moveLeft(distance);
            else if (window.event && window.event.keyCode == 38)
                playerShip.moveUp(distance);
            else if (window.event && window.event.keyCode == 39)
                playerShip.moveRight(distance);
            else if (window.event && window.event.keyCode == 40)
                playerShip.moveDown(distance);
        }
    </script>
</head>
<body onload="hello()"  onkeydown="move()">
<canvas id="playArea" width="400" height="400" ></canvas>
<input id="label" />
</body>
</html>
